﻿using InnoWeb.CEND.BL.Infrastructure;
using InnoWeb.CEND.Core.Model.Training;
using InnoWeb.CEND.Data;
using InnoWeb.CEND.Data.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InnoWeb.CEND.BL.Service.Training
{
    public class TrainingItemService: IService<TrainingItem>
    {
        private readonly GenericRepository<TrainingItem> _trainingItemRepository;
        private readonly IUnitOfWork _unitOfWork;

        public TrainingItemService(IUnitOfWork unitOfWork, GenericRepository<TrainingItem> trainingItemRepository)
        {
            this._trainingItemRepository = trainingItemRepository;
            this._unitOfWork = unitOfWork;
        }

        public IQueryable<TrainingItem> GetAllElements()
        {
            return _trainingItemRepository.GetAll();
        }

        public TrainingItem GetElementById(int id)
        {
            return _trainingItemRepository.GetById(id);
        }

        public void CreateElement(TrainingItem entity)
        {
            _trainingItemRepository.Insert(entity);
        }

        public void UpdateElement(TrainingItem entity)
        {
            _trainingItemRepository.Update(entity);
        }

        public void DeleteElement(int id)
        {
            _trainingItemRepository.Delete(id);
        }

        public void SaveChanges()
        {
            _unitOfWork.SaveChanges();
        }
    }
}
